<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2022/5/23
  Time: 16:44
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" href="/layui/css/layui.css">
    <script src="/layui/layui.js"></script>
    <script src="/layui/jquery-3.6.0.min.js"></script>
    <script>
        $(function () {
            layui.use(['laypage', 'layer'], function () {
                var laypage = layui.laypage
                    , layer = layui.layer;
                //分组件
                laypage.render({
                    elem: 'pagesData'
                    , count: ${pageInfo.total}
                    , layout: ['count', 'prev', 'page', 'next', 'limit', 'skip']
                    , limit: ${pageInfo.pageSize}
                    , limits: [5, 10, 15]
                    , curr:${pageInfo.pageNum}
                    , jump: function (obj,first) {
                        //首次不执行
                        if(!first){
                            if (obj.curr !=${pageInfo.pageNum}) {
                                location.href = "/video/findAll?page=" + obj.curr + "&limit=" + obj.limit
                            }else if(obj.limit!=${pageInfo.pageSize}){
                                location.href = "/video/findAll?page=1&limit=" + obj.limit
                            }
                        }
                    }


                });


            });

            $("#delAll").click(function () {
                $("input[name='ids']").prop("checked", $(this).prop("checked"))
            })
            $("#delAllIds").click(function () {
                console.log($("td > input[type='checkbox']:checked"))
                var ids = new Array();
                $("td > input[type='checkbox']:checked").each(function () {
                    ids.push($(this).val())
                })

                $.ajax({
                    type:"POST",
                    url:"/video/deleteIds",
                    data:JSON.stringify(ids),
                    contentType:"application/json;charset=utf-8",
                    success:function (data){
                        console.log(data)
                        location.href=data;
                    }
                });

            })


        })

        function delids(id, name) {
            //询问框
            layer.confirm('确定删除视频[' + name + ']？', {
                btn: ['确定', '取消'] //按钮
            }, function () {
                location.href = "/video/deleteById?id=" + id;
                // return true;
                //layer.msg('的确很重要', {icon: 1});
            }, function () {
                //  return false;
            });
        }
    </script>


</head>
<body>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>视频列表</legend>
</fieldset>
<div class="layui-bg-gray" style="padding: 0px;">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body">

                    <div class="layui-btn-group">
                        <a href="/page/video/video-add.jsp" class="layui-btn layui-btn-normal layui-btn-sm">
                            <i class="layui-icon ayui-icon-add-circle"></i>添加视频
                        </a>
                        <a class="layui-btn layui-btn-danger layui-btn-sm" id="delAllIds">
                            <i class="layui-icon layui-icon-delete"></i>批量删除视频
                        </a>

                    </div>
                    &nbsp; &nbsp; &nbsp; &nbsp;

                </div>


                <!--数据列表-->
                <table id="dataList" class="layui-table">
                    <thead>
                    <tr>
                        <th class="" style="padding-right: 0px;"><input
                                id="delAll" type="checkbox" class="icheckbox_square-blue">
                        </th>
                        <th>视频ID</th>
                        <th>课程名称</th>
                        <th>视频标题</th>
                        <th>视频文件URL</th>
                        <th>创建时间</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <c:forEach items="${pageInfo.list}" var="video">
                        <tr>
                            <td><input name="ids" type="checkbox" value="${video.id}"></td>
                            <td>${video.id}</td>
                            <td>${video.courseName}</td>
                            <td>${video.title}</td>
                            <td>${video.videoUrl}</td>
                            <td>${video.getCreatedTimeStr() }</td>
                            <td class="text-center">
                                    <%--详情--%>
                                <a title="视频详情" class="layui-btn layui-btn-normal layui-btn-xs"
                                   href="${pageContext.request.contextPath}/video/show?id=${video.id}"><i
                                        class="layui-icon layui-icon-align-center"></i> </a>
                                    <%--修改--%>
                                <a title="修改" class="layui-btn layui-btn-warm layui-btn-xs"
                                   href="${pageContext.request.contextPath}/video/findById?id=${video.id}"><i
                                        class="layui-icon layui-icon-set-fill"></i> <span
                                        class="glyphicon glyphicon-pencil"></span></a>
                                    <%--删除--%>
                                <button class="layui-btn layui-btn-danger layui-btn-xs" title="删除"
                                    <%--                                            href="${pageContext.request.contextPath}/product/deleteById?id=${product.id}"--%>
                                        onclick="delids(${video.id},'${video.title}')"><i
                                        class="layui-icon layui-icon-delete"></i> <span
                                        class="glyphicon glyphicon-trash"></span>
                                </button>
                            </td>
                        </tr>
                    </c:forEach>
                    </tbody>
                </table>
                <!--分页-->
                <div id="pagesData"></div>

            </div>
        </div>
    </div>
</div>
</div>
</body>
</html>
